package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/order"
	"github.com/streadway/amqp"
	"strconv"
)

//挂单超时取消挂单
func main() {
	mOrder := new(order.Temp).Init()
	defer mOrder.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("order.log.delTemp"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("order.queue.delTemp"), func(msg amqp.Delivery) {
		tempId, err  := strconv.Atoi( string(msg.Body) )
		if err != nil{
			utils.Logerr.Printf("挂单超时取消，tempId 转换int失败，tempId:%s, err:%s", string(msg.Body), err)
			return
		}
		var reply bool
		err = mOrder.MqCancelTemp(context.Background(), tempId, &reply)
		if err != nil {
			utils.Logerr.Printf("挂单超时取消，业务处理任务调用失败，tempId:%d, err:%s", tempId, err)
		}
	})

	if err != nil {
		utils.Logerr.Printf("挂单超时取消任务错误，err: %s", err.Error())
	}
}